package club.xyes.zkh.ecommerce.common.entity;

import club.xyes.zkh.ecommerce.common.context.ApplicationConstants;
import lombok.Data;

import javax.persistence.Column;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * Create by 郭文梁 2019/4/15 0015 11:53
 * BaseEntity
 * 实体类基类 提供公有属性和公有方法
 *
 * @author 郭文梁
 * @data 2019/4/15 0015
 */
@Data
public abstract class BaseEntity {
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private Date createTime;
    /**
     * 修改时间
     */
    @Column(name = "update_time")
    private Date updateTime;

    /**
     * 初始化BaseEntity中的属性
     *
     * @return BaseEntity
     */
    public BaseEntity init() {
        LocalDateTime now = LocalDateTime.now();
        Instant instant = now.atZone(ApplicationConstants.DEFAULT_TIMEZONE).toInstant();
        updateTime = createTime = Date.from(instant);
        return this;
    }
}
